
from datetime import date
import decimal
from sqlalchemy import DECIMAL, BigInteger, Column, Date, Integer, String, Text
from app.entity.baseModal import BaseModal
from sqlalchemy.orm import Mapped,mapped_column,declarative_base, relationship,sessionmaker

from app.entity.projectGroup import ProjectGroup
from app.entity.user import User

class ProjectDetails(BaseModal):
    __tablename__="jz_project_details"
    _fieldIgnore = []
    projectId :Mapped[int]=mapped_column(BigInteger(),name="project_id")
    title :Mapped[str]=mapped_column(String(100))
    remask :Mapped[str]=mapped_column(String(200))
    price :Mapped[decimal.Decimal]=mapped_column(DECIMAL())
    payDate:Mapped[date]=mapped_column(Date(),name="pay_date")
    payer :Mapped[int]=mapped_column(BigInteger())
    customPayer :Mapped[str]=mapped_column(String(100),name="custom_payer")
    payGroupId :Mapped[int]=mapped_column(Integer(),name="pay_group_id")
    createdBy :Mapped[int]=mapped_column(Integer(),name="created_by")

    def getPayDateAttr(self,value):
        return self._dateFormat(value)
    
    def getPayerDescAttr(self):
        name=self.customPayer
        user=User().query().filter(User.id==self.payer).with_entities(User.nickname).first()
        if user!=None:
            name=user.nickname
        return name
    
    def getPayGroupDescAttr(self):
        pg=ProjectGroup().query().filter(ProjectGroup.id==self.payGroupId).with_entities(ProjectGroup.name).first()
        return pg.name